<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Gestion_Des_Inscriptions_Universitaires:  Fichier source de /home/omid/Bureau/projet/gestion-des-inscriptions-universitaires-version-finale/src/UtilStr.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Généré par Doxygen 1.7.4 -->
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Gestion_Des_Inscriptions_Universitaires</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Page&#160;principale</span></a></li>
      <li><a href="pages.html"><span>Pages&#160;associées</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Fichiers</span></a></li>
      <li><a href="dirs.html"><span>Répertoires</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Liste&#160;des&#160;fichiers</span></a></li>
      <li><a href="globals.html"><span>Membres&#160;de&#160;fichier</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_util_str_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">UtilStr.c</div>  </div>
</div>
<div class="contents">
<a href="_util_str_8c.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="_util_str_8h.html" title="Fichier d&#39;entête du module utilitaireString.">UtilStr.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 
<a name="l00007"></a><a class="code" href="_util_str_8h.html#a690d54e00e307c4304ddecdc7d3287d3">00007</a> <span class="keywordtype">void</span> <a class="code" href="_util_str_8c.html#a690d54e00e307c4304ddecdc7d3287d3" title="Copie dans dest le la chaine src.">copStr</a>(<span class="keywordtype">char</span> ** dest, <span class="keyword">const</span> <span class="keywordtype">char</span> * src)
<a name="l00008"></a>00008 {
<a name="l00009"></a>00009   <span class="keywordflow">if</span>((*dest) != NULL)
<a name="l00010"></a>00010     {
<a name="l00011"></a>00011       free((*dest));
<a name="l00012"></a>00012       (*dest) = NULL;
<a name="l00013"></a>00013     }
<a name="l00014"></a>00014   <span class="keywordflow">if</span>(src)
<a name="l00015"></a>00015     {
<a name="l00016"></a>00016       (*dest) = (<span class="keywordtype">char</span> *) malloc ((1 + strlen(src)) * <span class="keyword">sizeof</span>(char));
<a name="l00017"></a>00017       <span class="keywordflow">if</span>((*dest) == NULL)
<a name="l00018"></a>00018         {
<a name="l00019"></a>00019           fprintf(stderr, <span class="stringliteral">&quot;Mémoire insuffisante&quot;</span>);
<a name="l00020"></a>00020           exit(EXIT_FAILURE);
<a name="l00021"></a>00021         }
<a name="l00022"></a>00022       strcpy((*dest), src);
<a name="l00023"></a>00023     }
<a name="l00024"></a>00024 }
<a name="l00025"></a>00025 
<a name="l00026"></a><a class="code" href="_util_str_8h.html#a394e79de443acac484a7dc55d44770fa">00026</a> <span class="keywordtype">void</span> <a class="code" href="_util_str_8c.html#a394e79de443acac484a7dc55d44770fa" title="Supprime de la mémoire un char, utile pour la généricité du code.">detStr</a>(<span class="keywordtype">char</span> ** uti)
<a name="l00027"></a>00027 {
<a name="l00028"></a>00028   <span class="keywordflow">if</span>((*uti))
<a name="l00029"></a>00029     {
<a name="l00030"></a>00030       free((*uti));
<a name="l00031"></a>00031       (*uti) = NULL;
<a name="l00032"></a>00032     }
<a name="l00033"></a>00033 }
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 
<a name="l00036"></a><a class="code" href="_util_str_8h.html#a92c201a8e2d3381da8c1a9414d29e2d2">00036</a> <span class="keywordtype">char</span> *<a class="code" href="_util_str_8c.html#a92c201a8e2d3381da8c1a9414d29e2d2">substr</a>(<span class="keywordtype">char</span> *src,<span class="keywordtype">int</span> pos,<span class="keywordtype">int</span> len)
<a name="l00037"></a>00037     {
<a name="l00038"></a>00038     <span class="keywordtype">char</span> *dest=NULL;
<a name="l00039"></a>00039     <span class="keywordflow">if</span> (len&gt;0)
<a name="l00040"></a>00040         {
<a name="l00041"></a>00041         dest = (<span class="keywordtype">char</span> *) malloc(len+1);
<a name="l00042"></a>00042         strncat(dest,src+pos,len);
<a name="l00043"></a>00043         }
<a name="l00044"></a>00044     <span class="keywordflow">return</span> dest;
<a name="l00045"></a>00045     }
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="_util_str_8h.html#a98f8e1781516cb7da38e7ae6e04f7734">00047</a> <span class="keywordtype">char</span> *<a class="code" href="_util_str_8c.html#a98f8e1781516cb7da38e7ae6e04f7734">str_join</a> (<span class="keywordtype">char</span> *cs, ...)
<a name="l00048"></a>00048     {
<a name="l00049"></a>00049     va_list va;
<a name="l00050"></a>00050     <span class="keyword">const</span> <span class="keywordtype">char</span> *ct;
<a name="l00051"></a>00051     <span class="keywordtype">char</span> *s = NULL;
<a name="l00052"></a>00052     <span class="keywordtype">size_t</span> size = 0;
<a name="l00053"></a>00053 
<a name="l00054"></a>00054     va_start (va, cs);
<a name="l00055"></a>00055     <span class="comment">/* (1) */</span>
<a name="l00056"></a>00056     <span class="keywordflow">while</span> ((ct = va_arg (va, <span class="keywordtype">char</span> *)) != NULL)
<a name="l00057"></a>00057         {
<a name="l00058"></a>00058         <span class="keywordtype">void</span> *tmp = NULL;
<a name="l00059"></a>00059 
<a name="l00060"></a>00060         <span class="comment">/* (2) */</span>
<a name="l00061"></a>00061         size += strlen (ct) + strlen (cs);
<a name="l00062"></a>00062         tmp = realloc (s, <span class="keyword">sizeof</span> (*s) * (size + 1));
<a name="l00063"></a>00063         <span class="keywordflow">if</span> (tmp != NULL)
<a name="l00064"></a>00064             {
<a name="l00065"></a>00065             <span class="keywordflow">if</span> (s == NULL)
<a name="l00066"></a>00066                 {
<a name="l00067"></a>00067                 <span class="comment">/* (3) */</span>
<a name="l00068"></a>00068                 s = tmp;
<a name="l00069"></a>00069                 strcpy (s, ct);
<a name="l00070"></a>00070                 }
<a name="l00071"></a>00071             <span class="keywordflow">else</span>
<a name="l00072"></a>00072                 {
<a name="l00073"></a>00073                 <span class="comment">/* (4) */</span>
<a name="l00074"></a>00074                 s = tmp;
<a name="l00075"></a>00075                 strcat (s, cs);
<a name="l00076"></a>00076                 strcat (s, ct);
<a name="l00077"></a>00077                 }
<a name="l00078"></a>00078             }
<a name="l00079"></a>00079         <span class="keywordflow">else</span>
<a name="l00080"></a>00080             {
<a name="l00081"></a>00081             fprintf (stderr, <span class="stringliteral">&quot;Memoire insuffisante\n&quot;</span>);
<a name="l00082"></a>00082             free (s);
<a name="l00083"></a>00083             s = NULL;
<a name="l00084"></a>00084             exit (EXIT_FAILURE);
<a name="l00085"></a>00085             }
<a name="l00086"></a>00086         }
<a name="l00087"></a>00087     <span class="keywordflow">return</span> s;
<a name="l00088"></a>00088     }
<a name="l00089"></a>00089 
<a name="l00090"></a><a class="code" href="_util_str_8h.html#a5c8976a2c7b858bc869af6b83354549a">00090</a> <span class="keywordtype">char</span> **<a class="code" href="_util_str_8c.html#a5c8976a2c7b858bc869af6b83354549a">str_split</a> (<span class="keywordtype">char</span> *s, <span class="keyword">const</span> <span class="keywordtype">char</span> *ct)
<a name="l00091"></a>00091     {
<a name="l00092"></a>00092     <span class="keywordtype">char</span> **tab = NULL;
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="keywordflow">if</span> (s != NULL &amp;&amp; ct != NULL)
<a name="l00095"></a>00095         {
<a name="l00096"></a>00096         <span class="keywordtype">int</span> i;
<a name="l00097"></a>00097         <span class="keywordtype">char</span> *cs = NULL;
<a name="l00098"></a>00098         <span class="keywordtype">size_t</span> size = 1;
<a name="l00099"></a>00099 
<a name="l00100"></a>00100         <span class="comment">/* (1) */</span>
<a name="l00101"></a>00101         <span class="keywordflow">for</span> (i = 0; (cs = strtok (s, ct)); i++)
<a name="l00102"></a>00102             {
<a name="l00103"></a>00103             <span class="keywordflow">if</span> (size &lt;= i + 1)
<a name="l00104"></a>00104                 {
<a name="l00105"></a>00105                 <span class="keywordtype">void</span> *tmp = NULL;
<a name="l00106"></a>00106 
<a name="l00107"></a>00107                 <span class="comment">/* (2) */</span>
<a name="l00108"></a>00108                 size &lt;&lt;= 1;
<a name="l00109"></a>00109                 tmp = realloc (tab, <span class="keyword">sizeof</span> (*tab) * size);
<a name="l00110"></a>00110                 <span class="keywordflow">if</span> (tmp != NULL)
<a name="l00111"></a>00111                     {
<a name="l00112"></a>00112                     tab = tmp;
<a name="l00113"></a>00113                     }
<a name="l00114"></a>00114                 <span class="keywordflow">else</span>
<a name="l00115"></a>00115                     {
<a name="l00116"></a>00116                     fprintf (stderr, <span class="stringliteral">&quot;Memoire insuffisante\n&quot;</span>);
<a name="l00117"></a>00117                     free (tab);
<a name="l00118"></a>00118                     tab = NULL;
<a name="l00119"></a>00119                     exit (EXIT_FAILURE);
<a name="l00120"></a>00120                     }
<a name="l00121"></a>00121                 }
<a name="l00122"></a>00122             <span class="comment">/* (3) */</span>
<a name="l00123"></a>00123             tab[i] = cs;
<a name="l00124"></a>00124             s = NULL;
<a name="l00125"></a>00125             }
<a name="l00126"></a>00126         tab[i] = NULL;
<a name="l00127"></a>00127         }
<a name="l00128"></a>00128     <span class="keywordflow">return</span> tab;
<a name="l00129"></a>00129     }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131 
<a name="l00132"></a><a class="code" href="_util_str_8h.html#a76236b9e320cff799d70a013ec171b66">00132</a> <span class="keywordtype">int</span> <a class="code" href="_util_str_8c.html#a76236b9e320cff799d70a013ec171b66">estUneDateDeLaSemaine</a>(<span class="keywordtype">char</span> * date)
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134 <span class="keywordflow">if</span>(date==NULL)<span class="keywordflow">return</span> -1;
<a name="l00135"></a>00135 <span class="keywordtype">char</span>*   date_1=calloc(40,<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>));
<a name="l00136"></a>00136 strcpy(date_1,date);
<a name="l00137"></a>00137 <span class="keywordtype">char</span> **tabDate=<a class="code" href="_util_str_8c.html#a5c8976a2c7b858bc869af6b83354549a">str_split</a>(date_1,<span class="stringliteral">&quot;--&quot;</span>);
<a name="l00138"></a>00138 <span class="keywordtype">int</span> annee=atoi(tabDate[0]);
<a name="l00139"></a>00139 <span class="keywordtype">int</span> <a class="code" href="_date_8c.html#a273956a68e89f91530aa8a4b33a94bb5">mois</a>=atoi(tabDate[1]);
<a name="l00140"></a>00140 <span class="keywordtype">int</span> <a class="code" href="_date_8c.html#acf90c01a7944bfe5a2563b69c830c0c9">jour</a>=atoi(tabDate[2]);
<a name="l00141"></a>00141 
<a name="l00142"></a>00142 
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 
<a name="l00145"></a>00145 
<a name="l00146"></a>00146     time_t timestamp;
<a name="l00147"></a>00147     <span class="keyword">struct </span>tm * t;
<a name="l00148"></a>00148 
<a name="l00149"></a>00149     timestamp = time(NULL);
<a name="l00150"></a>00150     t = localtime(&amp;timestamp);
<a name="l00151"></a>00151 
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 
<a name="l00155"></a>00155     <span class="keywordflow">if</span>(annee==t-&gt;tm_year+1900 &amp;&amp; mois==t-&gt;tm_mon+1 &amp;&amp; jour&lt;=(t-&gt;tm_mday+4) &amp;&amp; jour&gt;=(t-&gt;tm_mday-4))
<a name="l00156"></a>00156         {
<a name="l00157"></a>00157         free(date_1);
<a name="l00158"></a>00158                 <span class="keywordflow">return</span> 0;
<a name="l00159"></a>00159         }
<a name="l00160"></a>00160         free(date_1);
<a name="l00161"></a>00161         <span class="keywordflow">return</span> -1;
<a name="l00162"></a>00162     <span class="comment">/* Affiche la date et l&#39;heure courante (format francais) */</span>
<a name="l00163"></a>00163         <span class="comment">/*</span>
<a name="l00164"></a>00164 <span class="comment">    printf(&quot;Nous sommes %s, &quot;, NomJourSemaine[t-&gt;tm_wday]);</span>
<a name="l00165"></a>00165 <span class="comment">    printf(&quot;le %02u %s %04u, &quot;, t-&gt;tm_mday, NomMois[t-&gt;tm_mon], 1900 + t-&gt;tm_year);</span>
<a name="l00166"></a>00166 <span class="comment">    printf(&quot;et il est %02uh %02umin %02usec.\n&quot;, t-&gt;tm_hour, t-&gt;tm_min, t-&gt;tm_sec);</span>
<a name="l00167"></a>00167 <span class="comment">    */</span>
<a name="l00168"></a>00168 
<a name="l00169"></a>00169 
<a name="l00170"></a>00170 
<a name="l00171"></a>00171 
<a name="l00172"></a>00172 }
<a name="l00173"></a>00173 
<a name="l00178"></a><a class="code" href="_util_str_8h.html#ae1d581a4a3781026f9f24a56a73ef53e">00178</a> <span class="keywordtype">void</span> <a class="code" href="_util_str_8c.html#ae1d581a4a3781026f9f24a56a73ef53e" title="detTab">detTab</a>(<span class="keywordtype">void</span> ** tab)
<a name="l00179"></a>00179 {
<a name="l00180"></a>00180     <span class="keywordflow">if</span>(*tab==NULL)<span class="keywordflow">return</span>;
<a name="l00181"></a>00181     <a class="code" href="structs_tab_generique.html">TabGenerique</a>    *   tabGen=*tab;
<a name="l00182"></a>00182     <span class="keywordtype">int</span> i=0;
<a name="l00183"></a>00183     <span class="keywordflow">while</span>(i&lt;tabGen-&gt;nbElt)
<a name="l00184"></a>00184     {
<a name="l00185"></a>00185         free(tabGen-&gt;<a class="code" href="structs_tab_generique.html#a1af32e9e21af83d572aa3a249db60224">tab</a>[i]);
<a name="l00186"></a>00186         i++;
<a name="l00187"></a>00187     }
<a name="l00188"></a>00188     free(&amp;(tabGen-&gt;<a class="code" href="structs_tab_generique.html#a1af32e9e21af83d572aa3a249db60224">tab</a>));
<a name="l00189"></a>00189     tabGen-&gt;<a class="code" href="structs_tab_generique.html#a1af32e9e21af83d572aa3a249db60224">tab</a>=NULL;
<a name="l00190"></a>00190     tabGen-&gt;<a class="code" href="structs_tab_generique.html#a9c264a109c2c81594145220a30253042">nbElt</a>=0;
<a name="l00191"></a>00191     tab=NULL;
<a name="l00192"></a>00192     tabGen=NULL;
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_util_str_8c.html">UtilStr.c</a>      </li>
      <li class="footer">Généré le Thu Jun 7 2012 17:01:10 pour Gestion_Des_Inscriptions_Universitaires par&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </li>
    </ul>
  </div>

</body>
</html>
